﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Main_Accounts_TDSDedctorMaster : System.Web.UI.Page
{
    string strsql = string.Empty;
    Datautility DU = new Datautility();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            _BindSateToDropdownlist();
            _BindDedutorInformation();
            _BindResponsiblePersonInformation();
        }

    }
    private void _BindSateToDropdownlist()
    {
        strsql = "Select StateId,StateName from MAS_State order by StateName asc";
        DataTable DTState = DU.getdata(strsql);
        if (DTState.Rows.Count > 0)
        {
            //Bind Deductor State
            ddlDeductorState.DataSource = DTState;
            ddlDeductorState.DataTextField = "StateName";
            ddlDeductorState.DataValueField = "StateId";
            ddlDeductorState.DataBind();
            ddlDeductorState.Items.Insert(0, new ListItem("-Select-", "0"));
            //Bind Person State
            ddlPersonState.DataSource = DTState;
            ddlPersonState.DataTextField = "StateName";
            ddlPersonState.DataValueField = "StateId";
            ddlPersonState.DataBind();
            ddlPersonState.Items.Insert(0, new ListItem("-Select-", "0"));
        }        
    }
    private void _BindDedutorInformation()
    {
        DataTable DTDeductor = DU.getdatausingprocedure("USP_ACC_GetDeductor");
        if (DTDeductor.Rows.Count > 0)
        {
            txtDeuctorArea.Text = DTDeductor.Rows[0]["ADDRESS4"].ToString();
            txtDeuctorBranch.Text = DTDeductor.Rows[0]["BRANCH"].ToString();
            txtDeuctorBuilding.Text = DTDeductor.Rows[0]["ADDRESS2"].ToString();
            txtDeuctorCity.Text = DTDeductor.Rows[0]["ADDRESS5"].ToString();
            txtDeuctorEmail.Text = DTDeductor.Rows[0]["EMAILID"].ToString();
            txtDeuctorFax.Text = DTDeductor.Rows[0]["FAX"].ToString();
            txtDeuctorFlat.Text = DTDeductor.Rows[0]["ADDRESS1"].ToString();
            txtDeuctorName.Text = DTDeductor.Rows[0]["DEDUCTORNAME"].ToString();
            txtDeuctorPAN.Text = DTDeductor.Rows[0]["PAN"].ToString();
            txtDeuctorPincode.Text = DTDeductor.Rows[0]["PINCODE"].ToString();
            txtDeuctorSTDCode.Text = DTDeductor.Rows[0]["STDCODE"].ToString();
            txtDeuctorStreet.Text = DTDeductor.Rows[0]["ADDRESS3"].ToString();
            txtDeuctorTAN.Text = DTDeductor.Rows[0]["TANNO"].ToString();
            txtDeuctorTelephone.Text = DTDeductor.Rows[0]["TELEPHONE"].ToString();
            ddlDeductorAssessee.SelectedValue = DTDeductor.Rows[0]["ISTDSASSESSEE"].ToString();
            ddlDeductorChangeAddress.SelectedValue = DTDeductor.Rows[0]["ADDRESSCHANGED"].ToString();
            ddlDeductorState.SelectedValue = DTDeductor.Rows[0]["STATEID"].ToString();
            ddlDeductorStatus.SelectedValue = DTDeductor.Rows[0]["STATUSID"].ToString();
            ddlDeductorType.SelectedValue = DTDeductor.Rows[0]["DEDUCTORTYPE"].ToString();  
        }
    }
    private void _BindResponsiblePersonInformation()
    {
        DataTable DTPerson = DU.getdatausingprocedure("USP_ACC_GetResponsiblePerson");
        if (DTPerson.Rows.Count > 0)
        {
            txtPersonArea.Text = DTPerson.Rows[0]["ADDRESS4"].ToString();
            txtPersonBuilding.Text = DTPerson.Rows[0]["ADDRESS2"].ToString();
            txtPersonCity.Text = DTPerson.Rows[0]["ADDRESS5"].ToString();
            txtPersonDesignation.Text = DTPerson.Rows[0]["DESIGNATION"].ToString();
            txtPersonEmail.Text = DTPerson.Rows[0]["EMAILID"].ToString();
            txtPersonFatherName.Text = DTPerson.Rows[0]["FATHERNAME"].ToString();
            txtPersonFax.Text = DTPerson.Rows[0]["FAX"].ToString();
            txtPersonFlat.Text = DTPerson.Rows[0]["ADDRESS1"].ToString();
            txtPersonName.Text = DTPerson.Rows[0]["PERSONNAME"].ToString();
            txtPersonPincode.Text = DTPerson.Rows[0]["PINCODE"].ToString();
            txtPersonSTDCode.Text = DTPerson.Rows[0]["STDCODE"].ToString();
            txtPersonStreet.Text = DTPerson.Rows[0]["ADDRESS3"].ToString();
            txtPersonTelephone.Text =DTPerson.Rows[0]["TELEPHONE"].ToString();
            ddlPersonChangeAddress.SelectedValue = DTPerson.Rows[0]["ADDRESSCHANGED"].ToString();
            ddlPersonState.SelectedValue = DTPerson.Rows[0]["STATEID"].ToString();
            rbtPersonGender.SelectedValue=DTPerson.Rows[0]["GENDER"].ToString();
            
        }
    }
    private void _SaveDeductorInformation()
    {
        SqlParameter [] sparam=
                        {
                            new SqlParameter("@DEDUCTORNAME",txtDeuctorName.Text.Trim()),
                            new SqlParameter("@BRANCH",txtDeuctorBranch.Text.Trim()),
                            new SqlParameter("@ADDRESS1",txtDeuctorFlat.Text.Trim()),
                            new SqlParameter("@ADDRESS2",txtDeuctorBuilding.Text.Trim()),
                            new SqlParameter("@ADDRESS3",txtDeuctorStreet.Text.Trim()),
                            new SqlParameter("@ADDRESS4",txtDeuctorArea.Text.Trim()),
                            new SqlParameter("@ADDRESS5",txtDeuctorCity.Text.Trim()),
                            new SqlParameter("@STATEID",ddlDeductorState.SelectedValue),
                            new SqlParameter("@PINCODE",txtDeuctorPincode.Text.Trim()),
                            new SqlParameter("@ADDRESSCHANGED",ddlDeductorChangeAddress.SelectedValue),
                            new SqlParameter("@STDCODE",txtDeuctorSTDCode.Text.Trim()),
                            new SqlParameter("@TELEPHONE",txtDeuctorTelephone.Text.Trim()),
                            new SqlParameter("@FAX",txtDeuctorFax.Text.Trim()),
                            new SqlParameter("@EMAILID",txtDeuctorEmail.Text.Trim()),
                            new SqlParameter("@PAN",txtDeuctorPAN.Text.Trim()),
                            new SqlParameter("@TANNO",txtDeuctorTAN.Text.Trim()),
                            new SqlParameter("@ISTDSASSESSEE",ddlDeductorAssessee.SelectedValue),
                            new SqlParameter("@STATUSID",ddlDeductorStatus.SelectedValue),
                            new SqlParameter("@DEDUCTORTYPE",ddlDeductorType.SelectedValue)                            
                        };
        DU.executeprocedure("USP_ACC_SaveDeductor", sparam);
    }
    private void _SaveResponsiblePersonInformation()
    {
        SqlParameter[] sparam =
                        {
                            new SqlParameter("@PERSONNAME",txtPersonName.Text.Trim()),
                            new SqlParameter("@GENDER",rbtPersonGender.SelectedValue),
                            new SqlParameter("@DESIGNATION",txtPersonDesignation.Text.Trim()),
                            new SqlParameter("@FATHERNAME",txtPersonFatherName.Text.Trim()),
                            new SqlParameter("@ADDRESS1",txtPersonFlat.Text.Trim()),
                            new SqlParameter("@ADDRESS2",txtPersonBuilding.Text.Trim()),
                            new SqlParameter("@ADDRESS3",txtPersonStreet.Text.Trim()),
                            new SqlParameter("@ADDRESS4",txtPersonArea.Text.Trim()),
                            new SqlParameter("@ADDRESS5",txtPersonCity.Text.Trim()),
                            new SqlParameter("@STATEID",ddlPersonState.SelectedValue),
                            new SqlParameter("@PINCODE",txtPersonPincode.Text.Trim()),
                            new SqlParameter("@ADDRESSCHANGED",ddlPersonChangeAddress.SelectedValue),
                            new SqlParameter("@STDCODE",txtPersonSTDCode.Text.Trim()),
                            new SqlParameter("@TELEPHONE",txtPersonTelephone.Text.Trim()),
                            new SqlParameter("@FAX",txtPersonFax.Text.Trim()),
                            new SqlParameter("@EMAILID",txtPersonEmail.Text.Trim())                                                  
                        };
        DU.executeprocedure("USP_ACC_SaveResponsiblePerson", sparam);
    }
    protected void btnSave_OnClick(object sender, EventArgs e)
    {
        _SaveDeductorInformation();
        _SaveResponsiblePersonInformation();
        lblMsg.Text = "Updated Successfully...";
    }
    protected void btnCancel_OnClick(object sender, EventArgs e)
    {
        Response.Redirect("~/Welcome.aspx");
    }


}

                                            